public with sharing class ArticleController 
{
	private static String PARAM_ARTICLE_ID = 'articleId';
	
	public Article__c article {get;set;}
	
	public ArticleController()
	{
		String articleId = Apexpages.currentPage().getParameters().get(PARAM_ARTICLE_ID);
		try
		{
			this.article = [select id, publishDate__c, name, story__c from Article__c where status__c = 'published' and id = :articleId limit 1];
		}
		catch(System.Exception e)
		{
			System.debug(e.getMessage());
		}
	}
	
	public List<Article__c> getTop3Articles()
	{
		try
		{
			List<Article__c> articles = [select id, name, summary__c, publishDate__c from Article__c where status__c = 'published' order by publishDate__c desc limit 3];
			return articles;
		}
		catch(System.Exception e)
		{
			System.debug(e.getMessage());
		}
		return null;
	}
	
	public ApexPages.StandardSetController setController
	{
        get 
        {
            if(setController == null) 
            {
                setController = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select id, name, summary__c, publishDate__c from Article__c where status__c = 'published'order by publishDate__c desc]));
             setController.setPageSize(4);
                  
            }
            return setController;
        }
        set;
    }
	
	
	public List<Article__c> getAllArticles()
	{
		return (List<Article__c>) setController.getRecords();
	}
	
	// indicates whether there are more records after the current page set.
	public Boolean hasNext 
	{
		get 
		{
			return setController.getHasNext();
		}
		set;
	}
 
	// indicates whether there are more records before the current page set.
	public Boolean hasPrevious 
	{
		get 
		{
			return setController.getHasPrevious();
		}
		set;
	}
 
	// returns the page number of the current page set
	public Integer pageNumber 
	{
		get 
		{
			return setController.getPageNumber();
		}
		set;
	}
 
	// returns the first page of records
 	public void first() 
 	{
 		setController.first();
 	}
 
 	// returns the last page of records
 	public void last() 
 	{
 		setController.last();
 	}
 
 	// returns the previous page of records
 	public void previous() 
 	{
 		setController.previous();
 	}
 
 	// returns the next page of records
 	public void next() 
 	{
 		setController.next();
 	}
 
 	// returns the PageReference of the original page, if known, or the home page.
 	public void cancel() 
 	{
 		setController.cancel();
 	}
}